package com.stylefeng.guns.modular.pay.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.modular.pay.model.MchBus;
import com.stylefeng.guns.modular.pay.model.Trans;
import com.stylefeng.guns.modular.pay.service.IMchBusService;

/**
 * 交易流水控制器
 *
 * @author fengshuonan
 * @Date 2018-08-17 16:26:27
 */
@Controller
@RequestMapping("/mchBus")
public class MchBusController extends BaseController {

    private String PREFIX = "/pay/mchBus/";

    @Autowired
    private IMchBusService mchBusService;

    /**
     * 跳转到交易流水首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "mchBus.html";
    }

    /**
     * 跳转到添加交易流水
     */
    @RequestMapping("/mchBus_add")
    public String mchBusAdd() {
        return PREFIX + "mchBus_add.html";
    }

    /**
     * 跳转到修改交易流水
     */
    @RequestMapping("/mchBus_update/{mchBusId}")
    public String mchBusUpdate(@PathVariable Integer mchBusId, Model model) {
        MchBus mchBus = mchBusService.selectById(mchBusId);
        model.addAttribute("item",mchBus);
        LogObjectHolder.me().set(mchBus);
        return PREFIX + "mchBus_edit.html";
    }

    /**
     * 获取交易流水列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(MchBus condition) {
    	 Page<MchBus> page = new PageFactory<MchBus>().defaultPage();
    	 //商户数据过滤
    	 if(ShiroKit.getUser().getRoleList().contains(6)){
    		 String account = ShiroKit.getUser().getAccount();
    		 condition.setMchNo(account);
    	 }
         List<MchBus> result = mchBusService.list(page,condition);
         page.setRecords(result);
         return super.packForBT(page);
    }

    /**
     * 新增交易流水
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(MchBus mchBus) {
        mchBusService.insert(mchBus);
        return SUCCESS_TIP;
    }

    /**
     * 删除交易流水
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer mchBusId) {
        mchBusService.deleteById(mchBusId);
        return SUCCESS_TIP;
    }

    /**
     * 修改交易流水
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(MchBus mchBus) {
        mchBusService.updateById(mchBus);
        return SUCCESS_TIP;
    }

    /**
     * 交易流水详情
     */
    @RequestMapping(value = "/detail/{mchBusId}")
    @ResponseBody
    public Object detail(@PathVariable("mchBusId") Integer mchBusId) {
        return mchBusService.selectById(mchBusId);
    }
}
